/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package zpsb.accounting.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Michał
 */
@Entity
@Table(name = "invoices", catalog = "faktury", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Invoice.findAll", query = "SELECT i FROM Invoice i"),
    @NamedQuery(name = "Invoice.findById", query = "SELECT i FROM Invoice i WHERE i.id = :id"),
    @NamedQuery(name = "Invoice.findByAmount", query = "SELECT i FROM Invoice i WHERE i.amount = :amount"),
    @NamedQuery(name = "Invoice.findByDateOfIssue", query = "SELECT i FROM Invoice i WHERE i.dateOfIssue = :dateOfIssue"),
    @NamedQuery(name = "Invoice.findByDateOfSale", query = "SELECT i FROM Invoice i WHERE i.dateOfSale = :dateOfSale"),
    @NamedQuery(name = "Invoice.findByTermOfPayment", query = "SELECT i FROM Invoice i WHERE i.termOfPayment = :termOfPayment"),
    @NamedQuery(name = "Invoice.findByWayOfPayment", query = "SELECT i FROM Invoice i WHERE i.wayOfPayment = :wayOfPayment"),
    @NamedQuery(name = "Invoice.findByTotalNetPrice", query = "SELECT i FROM Invoice i WHERE i.totalNetPrice = :totalNetPrice"),
    @NamedQuery(name = "Invoice.findByStatus", query = "SELECT i FROM Invoice i WHERE i.status = :status"),
    @NamedQuery(name = "Invoice.findByTotalGross", query = "SELECT i FROM Invoice i WHERE i.totalGross = :totalGross"),
    @NamedQuery(name = "Invoice.findByNumber", query = "SELECT i FROM Invoice i WHERE i.number = :number"),
    @NamedQuery(name = "Invoice.findByType", query = "SELECT i FROM Invoice i WHERE i.type = :type"),
    @NamedQuery(name = "Invoice.findByTotalVat", query = "SELECT i FROM Invoice i WHERE i.totalVat = :totalVat")})
public class Invoice implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(nullable = false)
    private Integer id;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false, precision = 10, scale = 2)
    private BigDecimal amount;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_of_issue", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date dateOfIssue;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_of_sale", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date dateOfSale;
    @Column(name = "term_of_payment")
    @Temporal(TemporalType.DATE)
    private Date termOfPayment;
    @Size(max = 100)
    @Column(name = "way_of_payment", length = 100)
    private String wayOfPayment;
    @Basic(optional = false)
    @NotNull
    @Column(name = "total_net_price", nullable = false, precision = 10, scale = 2)
    private BigDecimal totalNetPrice;
    private Boolean status;
    @Basic(optional = false)
    @NotNull
    @Column(name = "total_gross", nullable = false, precision = 10, scale = 2)
    private BigDecimal totalGross;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 25)
    @Column(nullable = false, length = 25)
    private String number;
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    private int type;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 65535)
    @Column(nullable = false, length = 65535)
    private String comments;
    @Basic(optional = false)
    @NotNull
    @Column(name = "total_vat", nullable = false, precision = 10, scale = 2)
    private BigDecimal totalVat;
    @JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false)
    private User user;
    @JoinColumn(name = "customer_id", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false)
    private Customer customer;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "invoice")
    private List<Product> productList;

    public Invoice() {
    }

    public Invoice(Integer id) {
        this.id = id;
    }

    public Invoice(Integer id, BigDecimal amount, Date dateOfIssue, Date dateOfSale, BigDecimal totalNetPrice, BigDecimal totalGross, String number, int type, String comments, BigDecimal totalVat) {
        this.id = id;
        this.amount = amount;
        this.dateOfIssue = dateOfIssue;
        this.dateOfSale = dateOfSale;
        this.totalNetPrice = totalNetPrice;
        this.totalGross = totalGross;
        this.number = number;
        this.type = type;
        this.comments = comments;
        this.totalVat = totalVat;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public Date getDateOfIssue() {
        return dateOfIssue;
    }

    public void setDateOfIssue(Date dateOfIssue) {
        this.dateOfIssue = dateOfIssue;
    }

    public Date getDateOfSale() {
        return dateOfSale;
    }

    public void setDateOfSale(Date dateOfSale) {
        this.dateOfSale = dateOfSale;
    }

    public Date getTermOfPayment() {
        return termOfPayment;
    }

    public void setTermOfPayment(Date termOfPayment) {
        this.termOfPayment = termOfPayment;
    }

    public String getWayOfPayment() {
        return wayOfPayment;
    }

    public void setWayOfPayment(String wayOfPayment) {
        this.wayOfPayment = wayOfPayment;
    }

    public BigDecimal getTotalNetPrice() {
        return totalNetPrice;
    }

    public void setTotalNetPrice(BigDecimal totalNetPrice) {
        this.totalNetPrice = totalNetPrice;
    }

    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public BigDecimal getTotalGross() {
        return totalGross;
    }

    public void setTotalGross(BigDecimal totalGross) {
        this.totalGross = totalGross;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public BigDecimal getTotalVat() {
        return totalVat;
    }

    public void setTotalVat(BigDecimal totalVat) {
        this.totalVat = totalVat;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    @XmlTransient
    public List<Product> getProductList() {
        return productList;
    }

    public void setProductList(List<Product> productList) {
        this.productList = productList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Invoice)) {
            return false;
        }
        Invoice other = (Invoice) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "zpsb.accounting.model.Invoice[ id=" + id + " ]";
    }
    
}
